package com.shortUrl.starter.util;

import java.io.IOException;
import java.io.InputStream;

import io.vertx.core.json.JsonObject;

public class LoadConfigUtils {
    private static JsonObject config;

    private static String REDIS = "redis";
    static {
        try {
            InputStream is = LoadConfigUtils.class.getResourceAsStream("/config.json");
            StringBuffer sb = new StringBuffer();
            byte[] b = new byte[1024];
            int len = -1;
            while ((len = is.read(b)) != -1) {

                sb.append(new String(b, 0, len));
            }
            // System.out.println(new String(sb));
            config = new JsonObject(new String(sb));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static JsonObject getConfig() {
        return config;
    }

    public static JsonObject getRedisConfig() {
        return getConfig().getJsonObject(REDIS);
    }
}
